package com.hue.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.hue.springcloud.myhandler.CustomerBlockHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RateController {
    @GetMapping("/rate")
    @SentinelResource(value = "rate",blockHandler = "deal_rate")
    public String rate(){
        return "rate";
    }
    public String deal_rate(BlockException exception){
        return "rate被限流";
    }

    //不配置SentinelResource时如果该配置了流控规则，那么会调用默认的方法返回
    @GetMapping("/rate2")
    public String rate2(){
        return "rate2";
    }

    @GetMapping("/rate3")
    //调用统一的服务降级方法
    @SentinelResource(value = "rate3",blockHandlerClass = CustomerBlockHandler.class,blockHandler ="handler2")
    public String rate3(){
        return "rate3";
    }
}
